//
//  LGChartDetailView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/4.
//

#import "LGChartDetailAlertView.h"
#import "LGChartDetailAlertCell.h"
@interface LGChartDetailAlertView()<UITableViewDataSource,UITableViewDelegate>
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UITableView *tableView;

@end

@implementation LGChartDetailAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
//        self.cornerLayer.frame = self.bounds;
//        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.7];
        self.backgroundColor = [UIColor whiteColor];
        [self setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 1) opacity:0.35 radius:14];
        [self addSubview:self.tableView];
//        self.layer.mask = self.cornerLayer;
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.equalTo(self);
        }];
    }
    return self;
}

-(void)setDateString:(NSString *)dateString{
    _dateString = dateString;
    self.dateLabel.text = dateString;
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self.tableView reloadData];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGChartDetailAlertCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}


-(CAShapeLayer *)cornerLayer{
    if(!_cornerLayer){
        _cornerLayer = [[CAShapeLayer alloc]init];
        _cornerLayer.frame = self.bounds;
    }
    return _cornerLayer;
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, viewPix(50)) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGChartDetailAlertCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewPix(140), viewPix(30))];
        [headView addSubview:self.dateLabel];
        _tableView.tableHeaderView = headView;
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewPix(140), viewPix(5))];
    }
    return _tableView;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _dateLabel.frame = CGRectMake(viewPix(12), viewPix(5), viewPix(130), viewPix(25));
    }
    return _dateLabel;
}



@end
